// InsertCommand.java
package commands;
import utils.CommandStack;
import utils.EditorContext;

public class InsertCommand extends Command {
    private int lineNumber;
    private String text;

    public InsertCommand(EditorContext context, String text) {
        super(context);
        this.lineNumber = -1;
        this.text = text;
    }

    public InsertCommand(EditorContext context, int lineNumber, String text) {
        super(context);
        this.lineNumber = lineNumber;
        this.text = text;
    }

    @Override
    public void execute() {
        context.setSavingState(EditorContext.SavingState.ToSave);
        if(context.insert(lineNumber, text)){
//            System.out.println(context.getContent());
            CommandStack.getInstance().add(new InsertCommand(
                    new EditorContext(new StringBuilder(context.getContent())), lineNumber, text));
        }
    }
}
